package cn.yuan.xiaoyu.testmodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.yuan.xiaoyu.R;

/**
 * Created by yukuoyuan on 2017/9/20.
 * 这是一个跳转设置界面列表的适配器
 */
public class TestSettingAdapter extends RecyclerView.Adapter<TestSettingAdapter.MyHolder> {

    private List<String> listData;
    private OnItemClickListener onItemClickListener;

    public interface OnItemClickListener {
        void OnItemClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_test_setting, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        holder.tvItemTestSettingName.setText(listData.get(position));
        holder.tvItemTestSettingName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.OnItemClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        if (listData == null) {
            return 0;
        }
        return listData.size();
    }

    public void setData(List<String> listData) {
        this.listData = listData;
    }

    class MyHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_item_test_setting_name)
        TextView tvItemTestSettingName;

        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
